package com.example.administrator.myapplication;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.support.multidex.MultiDex;

import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.tencent.tinker.loader.app.DefaultApplicationLike;

/**
 * Description:
 * Author: MiraclesHed
 * Date: 2017/12/09
 * Email: miracleshed@163.com
 */

public class AppLike extends DefaultApplicationLike {

    public static final String TAG = "Tinker.AppLike";

    public AppLike(Application application, int tinkerFlags,
                   boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime,
                   long applicationStartMillisTime, Intent tinkerResultIntent) {
        super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, tinkerResultIntent);
    }


    @Override
    public void onCreate() {
        super.onCreate();
        //设置自定义升级对话框UI布局
        Beta.upgradeDialogLayoutId = R.layout.upgrade_dialog;
        //添加可显示弹窗的Activity
        Beta.canShowUpgradeActs.add(MainActivity.class);
        //TODO 初始化
        Bugly.init(getApplication(), "808641d70f", BuildConfig.LOG_DEBUG);
        //        Q：你们是怎么定义开发设备的？
        //        BitmapQrCodeDecoder：我们会提供接口Bugly.setIsDevelopmentDevice(getApplicationContext(), true);，
        //           我们后台就会将你当前设备识别为开发设备，如果设置为false则非开发设备，我们会根据这个配置进行策略控制。
        Bugly.setIsDevelopmentDevice(getApplication(), BuildConfig.LOG_DEBUG);
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    @Override
    public void onBaseContextAttached(Context base) {
        super.onBaseContextAttached(base);
        MultiDex.install(base);
        // 安装tinker
        // TinkerManager.installTinker(this); 替换成下面Bugly提供的方法
        Beta.installTinker(this);
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) {
        getApplication().registerActivityLifecycleCallbacks(callbacks);
    }

}
